package LineCode.剑指Offer.Utils;

import LineCode.剑指Offer.dto.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class TreeNodeUtil {

    public static void printListTreeNode(List<TreeNode> nodes) {
        for (TreeNode x : nodes)
            System.out.print(x.val);
        System.out.println();
    }

//    static  = new ArrayList<>();
    public static List<TreeNode> getPreOrderRec(List<TreeNode> result, TreeNode treeNode) {
        if (treeNode != null) {
            result.add(treeNode);
            getPreOrderRec(result, treeNode.left);
            getPreOrderRec(result, treeNode.right);
        }
        return result;
    }
    public static List<TreeNode> getInOrderRec(List<TreeNode> result, TreeNode treeNode) {
        if (treeNode != null) {
            getInOrderRec(result, treeNode.left);
            result.add(treeNode);
            getInOrderRec(result, treeNode.right);
        }
        return result;
    }
    public static List<TreeNode> getPostOrderRec(List<TreeNode> result, TreeNode treeNode) {
        if (treeNode != null) {
            getPostOrderRec(result, treeNode.left);
            getPostOrderRec(result, treeNode.right);
            result.add(treeNode);
        }
        return result;
    }


    public static void printTreeNode (TreeNode tn) {
        if (tn != null) {
            printTreeNode(tn.left);
            System.out.println("-" + tn.val + "-");
            printTreeNode(tn.right);
        }
    }

    public static TreeNode getOneTest1() {
        TreeNode J = new TreeNode(8, null, null);
        TreeNode H = new TreeNode(4, null, null);
        TreeNode G = new TreeNode(2, null, null);
        TreeNode F = new TreeNode(7, null, J);
        TreeNode E = new TreeNode(5, H, null);
        TreeNode D = new TreeNode(1, null, G);
        TreeNode C = new TreeNode(9, F, null);
        TreeNode B = new TreeNode(3, D, E);
        TreeNode A = new TreeNode(6, B, C);
        return A;
    }

}
